﻿using ERPEF.Model;
using ERPIService;
using Microsoft.EntityFrameworkCore;
using S4Project;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ERPService
{
    public class bs_employeeService : bs_employeeIService
    {
        private readonly MyDbContext MyDbContext;
        public bs_employeeService(MyDbContext myDb)
        {
            this.MyDbContext = myDb;
        }
        public async Task<int> Add(bs_employee bs_Employee)
        {
            await MyDbContext.bs_Employee.AddAsync(bs_Employee);
            return await MyDbContext.SaveChangesAsync();
        }

        public async Task<int> Delete(int employee_id)
        {
            var del = MyDbContext.bs_Employee.Find(employee_id);
            if (del != null)
            {
                del.IsDeleted = true;
                await MyDbContext.SaveChangesAsync();
                return 1;
            }
            return 0;
        }

        public async Task<List<bs_employee>> Query()
        {
            return await MyDbContext.bs_Employee
       .Where(w => w.IsDeleted == false)
       .ToListAsync();
        }

        public async Task<int> Update(bs_employee bs_Employee)
        {
            MyDbContext.bs_Employee.Update(bs_Employee);
            return await MyDbContext.SaveChangesAsync();
        }
    }
}
